<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<%@ taglib prefix="ujn" uri="http://ujn.edu.cn/common/" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName()
            + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML>
<html>

<head>
    <title>个人信息</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- 引入css样式文件 -->
    <!-- Bootstrap Core CSS -->
    <link href="<%=basePath%>css/bootstrap.css" rel="stylesheet"/>
    <!-- Bootstrap-grid CSS -->
    <link href="<%=basePath%>css/bootstrap-grid.css" rel="stylesheet"/>
    <!-- Bootstrap-reboot CSS -->
    <link href="<%=basePath%>css/bootstrap-reboot.css" rel="stylesheet"/>
    <!-- MetisMenu CSS -->
    <link href="<%=basePath%>css/metisMenu.min.css" rel="stylesheet" />
    <!-- DataTables CSS -->
    <link href="<%=basePath%>css/dataTables.bootstrap.css" rel="stylesheet" />
    <!-- Custom CSS -->
    <link href="<%=basePath%>css/sb-admin-2.css" rel="stylesheet" />
    <!-- Custom Fonts -->
    <link href="<%=basePath%>css/font-awesome.min.css" rel="stylesheet" type="text/css" />
    <link href="<%=basePath%>css/boot-crm.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>

<div>
    <nav class="navbar navbar-expand-lg navbar-dark " style="background-color:#81D8CF;;">
        <img src="imges/logo.jpg" class="rounded float-left" alt="Logo" height="45" width="45">
        <div class="container" style="">
            <a class="navbar-brand" href="#">停车场管理系统</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText"
                    aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarText">
                <ul class="navbar-nav mr-auto">
                    <li class="nav-item">
                        <a class="nav-link " href="${pageContext.request.contextPath }/userself">个人信息</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link " href="${pageContext.request.contextPath }/bookself">车位预定</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="${pageContext.request.contextPath}/payments">全部订单</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="${pageContext.request.contextPath}/coupon">优惠券</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link active" href="${pageContext.request.contextPath }/rateself">收费标准</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="${pageContext.request.contextPath }/vehicleself">车辆信息</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="${pageContext.request.contextPath }/userequip">投诉反馈</a>
                    </li>
                </ul>
                <span class="navbar-text">
          导航栏
        </span>
            </div>
        </div>
    </nav>
</div>
<%

    if (session.getAttribute("USER_SESSION")!=null) {
%>
<!--登录成功界面-->




<div class="container">
    <div class="p-2 bg-light border">
        <div class="row">

            <div class="panel panel-default">
                <div class="panel-body">
                    <form class="form-inline" method="get"
                          action="${pageContext.request.contextPath }/rate">
                        <div class="form-group">
                            <label for="vehicleType">车辆类型</label>
                            <select name="vehicleType" id="vehicleType" class="form-control" value="${vehicleType}">
                                <option value=""></option>
                                <option value="大型车">大型车</option>
                                <option value="小型车">小型车</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="spaceType">车辆类型</label>
                            <select name="spaceType" id="spaceType" class="form-control" value="${spaceType}">
                                <option value=""></option>
                                <option value="普通">普通</option>
                                <option value="VIP">VIP</option>
                                <option value="充电桩">充电桩</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="ratePerHour">收费/小时</label>
                            <input type="text" class="form-control" id="ratePerHour"
                                   value="${ratePerHour}" name="ratePerHour"/>
                        </div>
                        <button type="submit" class="btn btn-primary">查询</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
<%--    <a href="#" class="btn btn-primary" data-toggle="modal"--%>
<%--       data-target="#newUserDialog" onclick="clearRate()">新建</a>--%>
    <div class="p-2 bg-light border">
        <table class="table table-striped">
            <thead>
            <tr class="text-center">
                <th>收费标准</th>
                <th>车辆类型</th>
                <th>车位类型</th>
                <th>收费/小时</th>
<%--                <th>操作</th>--%>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${page.rows}" var="row">
                <tr class="text-center">
                    <td>${row.rateId}</td>
                    <td>${row.vehicleType}</td>
                    <td>${row.spaceType}</td>
                    <td>${row.ratePerHour}</td>
<%--                    <td>--%>
<%--                        <a href="#" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#userEditDialog"--%>
<%--                           onclick="editRate(${row.rateId})">修改</a>--%>
<%--                        <a href="#" class="btn btn-danger btn-xs" onclick="deleteRate(${row.rateId})">删除</a>--%>
<%--                    </td>--%>
                </tr>
            </c:forEach>
            </tbody>
        </table>
        <div class="col-md-12 text-right">
            <ujn:page url="${pageContext.request.contextPath }/rate"/>
        </div>
    </div>
</div>

<!-- 创建模态框 -->
<div class="modal fade" id="newUserDialog" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel1">收费标准</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="new_rate_form">

                    <div class="form-group">
                        <label for="new_vehicleType" class="col-sm-4 control-label">车辆类型</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="new_vehicleType" placeholder="用户类型" name="vehicleType">
                                <option value=""></option>
                                <option value="大型车">大型车</option>
                                <option value="小型车">小型车</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="new_spaceType" class="col-sm-4 control-label">车位类型</label>
                        <div class="col-sm-10">
                            <select class="form-control" id="new_spaceType" placeholder="车位类型" name="spaceType">
                                <option value=""></option>
                                <option value="普通">普通</option>
                                <option value="VIP">VIP</option>
                                <option value="充电桩">充电桩</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="new_ratePerHour" class="col-sm-3 control-label">收费/小时</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="new_ratePerHour" placeholder="收费/小时" name="ratePerHour" />
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>

                <button type="button" class="btn btn-primary" onclick="createRate()">新增收费标准</button>

            </div>
        </div>
    </div>
</div>
<!-- 修改模态框 -->
<%--<div class="modal fade" id="userEditDialog" tabindex="-1" role="dialog"--%>
<%--     aria-labelledby="myModalLabel">--%>
<%--    <div class="modal-dialog" role="document">--%>
<%--        <div class="modal-content">--%>
<%--            <div class="modal-header">--%>
<%--                <h4 class="modal-title" id="myModalLabel2">修改收费标准</h4>--%>
<%--                <button type="button" class="close" data-dismiss="modal" aria-label="Close">--%>
<%--                    <span aria-hidden="true">&times;</span>--%>
<%--                </button>--%>
<%--            </div>--%>
<%--            <div class="modal-body">--%>
<%--                <form class="form-horizontal" id="edit_rate_form">--%>
<%--                    <input type="hidden" id="edit_rateId" name="rateId"/>--%>

<%--                    <div class="form-group">--%>
<%--                        <label for="edit_vehicleType" class="col-sm-3 control-label">车辆类型</label>--%>
<%--                        <div class="col-sm-10">--%>
<%--                            <input type="text" class="form-control" id="edit_vehicleType" placeholder="车辆类型" name="vehicleType" />--%>
<%--                        </div>--%>
<%--                    </div>--%>
<%--                    <div class="form-group">--%>
<%--                        <label for="edit_spaceType" class="col-sm-3 control-label">车位类型</label>--%>
<%--                        <div class="col-sm-10">--%>
<%--                            <input type="text" class="form-control" id="edit_spaceType" placeholder="车位类型" name="spaceType" />--%>
<%--                        </div>--%>
<%--                    </div>--%>
<%--                    <div class="form-group">--%>
<%--                        <label for="edit_ratePerHour" class="col-sm-3 control-label">收费/小时</label>--%>
<%--                        <div class="col-sm-10">--%>
<%--                            <input type="text" class="form-control" id="edit_ratePerHour" placeholder="收费/小时" name="ratePerHour" />--%>
<%--                        </div>--%>
<%--                    </div>--%>

<%--                </form>--%>
<%--            </div>--%>
<%--            <div class="modal-footer">--%>
<%--                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>--%>
<%--                <button type="button" class="btn btn-primary" onclick="updateRate()">保存修改</button>--%>
<%--            </div>--%>
<%--        </div>--%>
<%--    </div>--%>
<%--</div>--%>
<%
} else{
%>
<!--登陆失败界面-->
<div class="jumbotron jumbotron-fluid">
    <div class="container">
        <h1 class="display-4">欢迎您,登录后即可查看</h1>
        <p class="lead">
            <a href="${pageContext.request.contextPath}/login">Welcome, log in to view</a>
        </p>
    </div>
</div>
<%  }
%>
<!-- 引入js文件 -->
<script src="<%=basePath%>js/jquery-1.11.3.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="<%=basePath%>js/bootstrap.js"></script>
<!-- Bootstrap-bundle JavaScript -->
<script src="<%=basePath%>js/bootstrap.bundle.js"></script>
<!-- Metis Menu Plugin JavaScript -->
<script src="<%=basePath%>js/metisMenu.min.js"></script>
<!-- DataTables JavaScript -->
<script src="<%=basePath%>js/jquery.dataTables.min.js"></script>
<script src="<%=basePath%>js/dataTables.bootstrap.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="<%=basePath%>js/sb-admin-2.js"></script>
<!-- 编写js代码 -->
<script type="text/javascript">
    //清空新建窗口中的数据
    function clearRate() {
        $("#new_ratePerHour").val("")
        $("#new_spaceType").val("")
        $("#new_vehicleType").val("")
    }

    // 创建
    function createRate() {
        $.post("<%=basePath%>rate",
            $("#new_rate_form").serialize(), function (data) {
                if (data == "OK") {
                    alert("用户创建成功！");
                    window.location.reload();
                } else {
                    alert("用户创建失败！");
                    window.location.reload();
                }
            });
    }

    // 通过id获取修改的用户信息
    function editRate(id) {
        $.ajax({
            type: "get",
            url: "<%=basePath%>rate/" + id,
            success: function (data) {
                $("#edit_rateId").val(data.rateId);
                $("#edit_spaceType").val(data.spaceType);
                $("#edit_vehicleType").val(data.vehicleType);
                $("#edit_ratePerHour").val(data.ratePerHour)

            }
        });
    }

    // 执行修改操作
    function updateRate() {
        var rateId = $("#edit_rateId").val();
        var spaceType = $("#edit_spaceType").val();
        var vehicleType = $("#edit_vehicleType").val();
        var ratePerHour = $("#edit_ratePerHour").val();
        $.ajax({
            url: '<%=basePath%>rate',
            type: 'PUT',
            data: JSON.stringify({
                rateId: rateId,
                vehicleType: vehicleType ,
                spaceType: spaceType,
                ratePerHour: ratePerHour,
            }),
            contentType: "application/json;charset=UTF-8",
            success: function (data) {
                if (data == "OK") {
                    alert("用户信息更新成功！");
                    window.location.reload();
                } else {
                    alert("用户信息更新失败！");
                    window.location.reload();
                }
            }
        });
    }

    // 删除
    function deleteRate(id) {
        if (confirm('确实要删除该收费标准吗?')) {
            $.ajax({
                url: '<%=basePath%>rate/' + id,
                type: 'DELETE',
                success: function (data) {
                    if (data == "OK") {
                        alert("用户信息删除成功！");
                        window.location.reload();
                    } else {
                        alert("用户信息删除失败！");
                        window.location.reload();
                    }
                }
            });
        }
    }
</script>
</body>

</html>
